<?php
namespace app\index\controller;

use app\common\model\Chat;
use app\common\model\Info;
use app\common\model\Qqjob;
use app\common\model\Qqs;
use app\common\model\Users;
use app\common\model\Weblist;

class Index extends Common
{
	public function _empty()
    {
        return $this->fetch('common/empty');
    }
	
    public function index()
    {
		$check_Login = Users::checkLogin();
        if ($check_Login == null) {
            $this->assign('islogin', 1);
            $this->userInfo = Users::getLoginUser();
			$this->assign('userInfo', $this->userInfo);
        }else{
			$this->assign('islogin', 0);
		}
        $newuser = Users::order('time desc')->limit(16)->select();
        $this->assign('users', $newuser);
		$this->assign('tcount', Weblist::start_Time());
        $this->assign('icount', Info::allYxCount());
        $this->assign('jcount', Qqjob::where('zid', '=', WEB_ID)->count());
        $this->assign('ucount', Users::where('web_id', '=', WEB_ID)->count());
        $this->assign('qcount', Qqs::where('web_id', '=', WEB_ID)->count());
        if(check_mobile()){
			return $this->fetch('index/wap/index');
		}else{
			return $this->fetch('index/web/index');
		}
    }
	
	public function login()
    {
		$check_Login = Users::checkLogin();
		if($check_Login != null){
			$this->assign('webTitle', '用户登录');
			if(check_mobile()){
				return $this->fetch('index/wap/login');
			}else{
				return $this->fetch('index/web/login');
			}
			
		}else{
            $this->assign('userInfo', Users::getLoginUser());
			$this->assign('webTitle', '快捷登陆');
			if(check_mobile()){
				return $this->fetch('index/wap/lock');
			}else{
				return $this->fetch('index/web/lock');
			}
		}
    }
	
	public function find()
    {
		$this->assign('webTitle', '找回密码');
		if(check_mobile()){
			return $this->fetch('index/wap/find');
		}else{
			return $this->fetch('index/web/find');
		}
    }
	
	public function reg()
    {
		$check_Login = Users::checkLogin();
		if($check_Login != null){
			$this->assign('webTitle', '用户注册');
			if(check_mobile()){
				return $this->fetch('index/wap/reg');
			}else{
				return $this->fetch('index/web/reg');
			}
		}else{
            $this->assign('userInfo', Users::getLoginUser());
			$this->assign('webTitle', '快捷登陆');
			if(check_mobile()){
				return $this->fetch('index/wap/lock');
			}else{
				return $this->fetch('index/web/lock');
			}
		}
    }
	
	public function logout()
    {
		$check_Login = Users::checkLogin();
        if ($check_Login == null) {
            $this->assign('islogin', 1);
            $this->userInfo = Users::getLoginUser();
			$this->assign('userInfo', $this->userInfo);
        }else{
			$this->assign('islogin', 0);
		}
        $newuser = Users::order('time desc')->limit(16)->select();
        $this->assign('users', $newuser);
		$this->assign('tcount', Weblist::start_Time());
        $this->assign('icount', Info::allYxCount());
        $this->assign('jcount', Qqjob::where('zid', '=', WEB_ID)->count());
        $this->assign('ucount', Users::where('web_id', '=', WEB_ID)->count());
        $this->assign('qcount', Qqs::where('web_id', '=', WEB_ID)->count());
        if (Users::logout()) {
			if(check_mobile()){
				exit ($this->fetch('index/wap/index'));
			}else{
				exit ($this->fetch('index/web/index'));
			}
        }
    }
}
